package com.hakim.wfb.platform.controller;

import com.hakim.wfb.customer.params.wallet.GetCoinMarketPriceParam;
import com.hakim.wfb.customer.params.wallet.GetUserWalletParameter;
import com.hakim.wfb.customer.result.wallet.CoinMarketPriceResult;
import com.hakim.wfb.customer.result.wallet.UserWalletView;
import com.hakim.wfb.customer.service.WalletService;
import com.hkfs.fundamental.api.data.ObjectResultEx;
import com.hkfs.fundamental.api.params.SessionIdentity;
import com.hkfs.fundamental.session.SessionHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2017/7/31.
 */
@RestController
@RequestMapping(value = "/wallet")
public class WalletController {

    private final Logger logger = LoggerFactory.getLogger(WalletController.class);

    @Autowired
    private WalletService walletService;

    /**
     * @param param
     * @return
     */
    @RequestMapping(value = "/userwallet", name = "获取用户钱包地址", method = RequestMethod.POST)
    public ObjectResultEx<UserWalletView> getUserWallet(GetUserWalletParameter param, HttpServletRequest request) {
        ObjectResultEx<UserWalletView> resultObjectResultEx = new ObjectResultEx<>();
        try {

            SessionHandler handler = new SessionHandler();
            SessionIdentity identity = handler.getSessionIdentity(request, SessionIdentity.class);
            param.setUserId(identity.getUuid());

            resultObjectResultEx = walletService.getUserWallet(param);
        } catch (Exception e) {
            logger.error("Error occurred." + e.getMessage());
        }
        return resultObjectResultEx;
    }

    /**
     * 久福币当前市场价格
     *
     * @param param
     * @param request
     * @return
     */
    @RequestMapping(value = "/coinprice", name = "久福币当前市场价格", method = RequestMethod.POST)
    public ObjectResultEx<CoinMarketPriceResult> getCoinMarketPrice(GetCoinMarketPriceParam param, HttpServletRequest request) {

        ObjectResultEx<CoinMarketPriceResult> resultObjectResultEx = new ObjectResultEx<>();
        try {
            resultObjectResultEx = walletService.getCoinCurrentPrice(param);
        } catch (Exception e) {
            logger.error("Error occurred." + e.getMessage());
        }
        return resultObjectResultEx;
    }
}
